<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全部文件</title>
    <script src="js/jQuery.js"></script>
    <SCRIPT src="component/layui/layui.js"></SCRIPT>
    <link rel="stylesheet" href="component/layui/css/layui.css"/>
    <script src="js/allFilesManager.js"></script>
    <link rel="stylesheet" href="admin/css/pear-icon/demo.css">
    <link rel="stylesheet" href="admin/css/pear-icon/iconfont.css">
</head>
<body style="padding-top: 20px">
<form class="layui-form">
    <div class="layui-form-item">
        <div style="text-align: right">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input class="layui-input " id="filename" type="text" placeholder="搜索你的文件">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-sm" onclick="getFilesList()">
                        <i class="layui-icon layui-icon-search"></i>查询</a>
                </div>
            </div>
        </div>
    </div>
</form>

<table class="layui-table" lay-filter="allFilesDemo" lay-size="sm" id="allFilesTable" style="height: 100%; width: 100%">

</table>

<div id="allFilesTable_page"></div>


</body>
<script type="text/html" id="toolbar">
    <div>
        <form action="##" id="uploadFold" name="uploadFold" enctype="multipart/form-data" method="post" hiidden>
            <input id="file" type="file" name="file" multiple webkitdirectory onchange="change()" hidden/>
            <input id="path" type="text" name="path" hidden/>
            <input id="id" type="text" name="id" hidden/>
        </form>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="returnParentFolder()"><i
                class="layui-icon layui-icon-return"></i></a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="uplaodFolder()"><i
                class="layui-icon"></i>上传文件夹</a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="uplaod()"><i
                class="layui-icon layui-icon-upload-drag"></i>上传文件</a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="addFloder()"><i
                class="layui-icon layui-icon-add-circle-fine"></i>新建文件夹</a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="ObsDownload()"><i
                class="layui-icon layui-icon-download-circle"></i>下载文件</a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="ObsCopy()">复制到</a>
        <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="ObsMove()">移动到</a>
    </div>
</script>

<script>
    //上传文件
    function uplaod() {
        layui.use('layer', function () {
            var $ = layui.jquery, layer = layui.layer;
            layer.open({
                type: 2 //Page层类型
                , area: ['700px', '400px']
                , title: '文件选择'
                , shade: 0.6 //遮罩透明度
                , maxmin: true //允许全屏最小化
                , content: 'uplaod.html',
                cancel: function (index, layero) {
                    getAllFilesList(curr-1, 10);
                },
                end: function () {//无论是确认还是取消，只要层被销毁了，end都会执行，不携带任何参数。layer.open关闭事件
                    getAllFilesList(curr-1, 10);
                }
            });
        });
    }

    //上传文件夹
    function uplaodFolder() {
        document.getElementById("file").click();
        document.getElementById("id").value = sessionStorage.getItem("id");
        document.getElementById("path").value = sessionStorage.getItem("filePath");


    }

    function change() {
        var form = new FormData(document.forms.namedItem("uploadFold"));//创建formData

        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: sessionStorage.getItem("rootPath") + "/files/uploadFolder",
            data: form,
            processData: false,			//对数据不做处理
            cache:false,      				//上传文件不需要缓存
            contentType: false,
            mimeType:"multipart/form-data",
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)

                layer.msg("上传成功！", {icon: 1, time: 1000}, function () {
                    getAllFilesList(curr - 1, 10);
                    layer.close(index);
                });

            },
            error: function () {
                alert("异常！");
            }
        });
    }

</script>
</html>